﻿'/* Copyright (c) 2009, Graeme Grant (graeme@live.com.au)
' * All rights reserved.
' *
' * Redistribution and use in source and binary forms, with or without
' * modification, are permitted provided that the following conditions are met:
' *
' *   * Redistributions of source code must retain the above copyright
' *     notice, this list of conditions and the following disclaimer.
' * 
' *   * Redistributions in binary form must reproduce the above copyright
' *     notice, this list of conditions and the following disclaimer in the
' *     documentation and/or other materials provided with the distribution.
' * 
' *   * The name Graeme Grant may not be used to endorse or promote products
' *     derived from this software without specific prior written permission.
' *
' * THIS SOFTWARE IS PROVIDED BY GRAEME GRANT ``AS IS'' AND ANY
' * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
' * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
' * DISCLAIMED. IN NO EVENT SHALL Dr. WPF BE LIABLE FOR ANY
' * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
' * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
' * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
' * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
' * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
' * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
' */

Imports System.Xml.Serialization
Imports System.IO

<Serializable()> _
Public Class User

#Region "Constructor"

    Public Sub New()

    End Sub

    Public Sub New(ByVal Details As Hashtable)
        ExtractDetails(Details)
    End Sub

    Friend Sub New(ByVal _json As String)
        ExtractDetails(CType(JSON.JsonDecode(_json), Hashtable)("results")(0))
    End Sub

#End Region

#Region "Public Properties"

    <XmlElement("user_name")> _
    Private _user_name As String
    Public Property UserName() As String
        Get
            Return _user_name
        End Get
        Set(ByVal value As String)
            _user_name = value
        End Set
    End Property

    <XmlElement("user_id")> _
    Private _user_id As Long
    Public Property UserID() As Long
        Get
            Return _user_id
        End Get
        Set(ByVal value As Long)
            _user_id = value
        End Set
    End Property

    <XmlElement("url")> _
    Private _url As String
    Public Property URL() As String
        Get
            Return _url
        End Get
        Set(ByVal value As String)
            _url = value
        End Set
    End Property

    <XmlElement("image_url_25x25")> _
    Private _image_url_25x25 As String
    Public Property ImageURL25x25() As String
        Get
            Return _image_url_25x25
        End Get
        Set(ByVal value As String)
            _image_url_25x25 = value
        End Set
    End Property

    <XmlElement("image_url_30x30")> _
    Private _image_url_30x30 As String
    Public Property ImageURL30x30() As String
        Get
            Return _image_url_30x30
        End Get
        Set(ByVal value As String)
            _image_url_30x30 = value
        End Set
    End Property

    <XmlElement("image_url_50x50")> _
    Private _image_url_50x50 As String
    Public Property ImageURL50x50() As String
        Get
            Return _image_url_50x50
        End Get
        Set(ByVal value As String)
            _image_url_50x50 = value
        End Set
    End Property

    <XmlElement("image_url_75x75")> _
    Private _image_url_75x75 As String
    Public Property ImageURL75x75() As String
        Get
            Return _image_url_75x75
        End Get
        Set(ByVal value As String)
            _image_url_75x75 = value
        End Set
    End Property

    <XmlElement("join_epoch")> _
    Private _join As Date
    Public Property Join() As Date
        Get
            Return _join
        End Get
        Set(ByVal value As Date)
            _join = value
        End Set
    End Property

    <XmlElement("city")> _
    Private _city As String
    Public Property City() As String
        Get
            Return _city
        End Get
        Set(ByVal value As String)
            _city = value
        End Set
    End Property

    <XmlElement("gender")> _
    Private _gender As String
    Public Property Gender() As String
        Get
            Return _gender
        End Get
        Set(ByVal value As String)
            _gender = value
        End Set
    End Property

    <XmlElement("lat")> _
    Private _lat As Single
    Public Property Lat() As Single
        Get
            Return _lat
        End Get
        Set(ByVal value As Single)
            _lat = value
        End Set
    End Property

    <XmlElement("lon")> _
    Private _lon As Single
    Public Property Lon() As Single
        Get
            Return _lon
        End Get
        Set(ByVal value As Single)
            _lon = value
        End Set
    End Property

    <XmlElement("transaction_buy_count")> _
    Private _transaction_buy_count As Integer
    Public Property TransactionBuyCount() As Integer
        Get
            Return _transaction_buy_count
        End Get
        Set(ByVal value As Integer)
            _transaction_buy_count = value
        End Set
    End Property

    <XmlElement("transaction_sold_count")> _
    Private _transaction_sold_count As Integer
    Public Property TransactionSoldCount() As Integer
        Get
            Return _transaction_sold_count
        End Get
        Set(ByVal value As Integer)
            _transaction_sold_count = value
        End Set
    End Property

    <XmlElement("is_seller")> _
    Private _is_seller As Boolean
    Public Property IsSeller() As Boolean
        Get
            Return _is_seller
        End Get
        Set(ByVal value As Boolean)
            _is_seller = value
        End Set
    End Property

    <XmlElement("was_featured_seller")> _
    Private _was_featured_seller As Boolean
    Public Property WasFeaturedSeller() As Boolean
        Get
            Return _was_featured_seller
        End Get
        Set(ByVal value As Boolean)
            _was_featured_seller = value
        End Set
    End Property

    <XmlArray("materials"), XmlArrayItem("material", IsNullable:=True)> _
    Private _materials As ArrayList
    Public Property Materials() As ArrayList
        Get
            Return _materials
        End Get
        Set(ByVal value As ArrayList)
            _materials = value
        End Set
    End Property

    <XmlElement("last_login_epoch")> _
    Private _last_login As Date
    Public Property LastLogin() As Date
        Get
            Return _last_login
        End Get
        Set(ByVal value As Date)
            _last_login = value
        End Set
    End Property

    <XmlElement("referred_user_count")> _
    Private _referred_user_count As Integer
    Public Property ReferredUserCount() As Integer
        Get
            Return _referred_user_count
        End Get
        Set(ByVal value As Integer)
            _referred_user_count = value
        End Set
    End Property

    <XmlElement("birth_day")> _
    Private _birth_day As Integer
    Public Property DayOfBirth() As Integer
        Get
            Return _birth_day
        End Get
        Set(ByVal value As Integer)
            _birth_day = value
        End Set
    End Property

    <XmlElement("birth_month")> _
    Private _birth_month As Integer
    Public Property MonthOfBrith() As Integer
        Get
            Return _birth_month
        End Get
        Set(ByVal value As Integer)
            _birth_month = value
        End Set
    End Property

    <XmlElement("bio")> _
    Private _bio As String
    Public Property Bio() As String
        Get
            Return _bio
        End Get
        Set(ByVal value As String)
            _bio = value
        End Set
    End Property

    <XmlElement("feedback_coun")> _
    Private _feedback_count As Integer
    Public Property FeedbackCount() As Integer
        Get
            Return _feedback_count
        End Get
        Set(ByVal value As Integer)
            _feedback_count = value
        End Set
    End Property

    <XmlElement("feedback_percent_positive")> _
    Private _feedback_percent_positive As Integer
    Public Property FeedbackPercentPositive() As Integer
        Get
            Return _feedback_percent_positive
        End Get
        Set(ByVal value As Integer)
            _feedback_percent_positive = value
        End Set
    End Property

    <XmlEnum("status")> _
    Private _status As Enums.user_status
    Public Property Status() As Enums.user_status
        Get
            Return _status
        End Get
        Set(ByVal value As Enums.user_status)
            _status = value
        End Set
    End Property

#End Region

#Region "Support Methods & Functions"

    Private Sub ExtractDetails(ByVal Details As Hashtable)

        _user_name = Details("user_name")
        _user_id = JSON.ToInteger(Details("user_id"))
        _url = Details("url")
        _image_url_25x25 = Details("image_url_25x25")
        _image_url_30x30 = Details("image_url_30x30")
        _image_url_50x50 = Details("image_url_50x50")
        _image_url_75x75 = Details("image_url_75x75")
        _join = JSON.DecodeDateTime(Details("join_epoch"))
        _city = Details("city")
        _gender = Details("gender")
        _lat = CSng(Details("lat"))
        _lon = CSng(Details("lon"))
        _transaction_buy_count = JSON.ToInteger(Details("transaction_buy_count"))
        _transaction_sold_count = JSON.ToInteger(Details("transaction_sold_count"))
        _is_seller = CBool(Details("is_seller"))
        _was_featured_seller = CBool(Details("was_featured_seller"))
        _materials = Details("materials")
        _last_login = JSON.DecodeDateTime(Details("last_login_epoch"))
        _referred_user_count = JSON.ToInteger(Details("referred_user_count"))
        _birth_day = JSON.ToInteger(Details("birth_day"))
        _birth_month = JSON.ToInteger(Details("birth_month"))
        _bio = Details("bio")
        _feedback_count = JSON.ToInteger(Details("feedback_count"))
        _feedback_percent_positive = JSON.ToInteger(Details("feedback_percent_positive"))
        Select Case Details("status")
            Case "public" : _status = Enums.user_status.Public
            Case "private" : _status = Enums.user_status.Private
        End Select

    End Sub

#End Region

End Class
